package com.gec.zhs.entity.pojo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gec.zhs.entity.dto.UserMessageExtendDto;
import com.gec.zhs.entity.enums.DateTimePatternEnum;
import com.gec.zhs.utils.DateUtil;
import com.gec.zhs.utils.JsonUtils;
import com.gec.zhs.utils.StringTools;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;


/**
 * @author zhs
 * @version 1.0
 * @date 2025-01-06
 * @description 用户消息表
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserMessage implements Serializable {


    /**
     * 消息ID自增
     */
    private Integer messageId;

    /**
     * 用户ID
     */
    private String userId;

    /**
     * 主体ID
     */
    private String videoId;

    /**
     * 消息类型
     */
    private Integer messageType;

    /**
     * 发送人ID
     */
    private String sendUserId;

    /**
     * 0:未读 1:已读
     */
    private Integer readType;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 扩展信息
     */
    private String extendJson;

    //消息体
    private UserMessageExtendDto extendDto;

    /**
     * 视频名称
     */
    private String videoName;

    /**
     * 视频内容
     */
    private String videoCover;

    /**
     * 发送人的昵称
     */
    private String sendUserName;

    /**
     * 发送人的头像
     */
    private String sendUserAvatar;


    public UserMessageExtendDto getExtendDto() {
        return StringTools.isEmpty(extendJson)?new UserMessageExtendDto(): JsonUtils.convertJsonToObj(extendJson, UserMessageExtendDto.class);
    }



    @Override
    public String toString() {
        return "消息ID自增:" + (messageId == null ? "空" : messageId) + "，用户ID:" + (userId == null ? "空" : userId) + "，主体ID:" + (videoId == null ? "空" : videoId) + "，消息类型:" + (messageType == null ? "空"
                : messageType) + "，发送人ID:" + (sendUserId == null ? "空" : sendUserId) + "，0:未读 1:已读:" + (readType == null ? "空" : readType) + "，创建时间:" + (createTime == null ? "空" : DateUtil.format(
                createTime,
                DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern())) + "，扩展信息:" + (extendJson == null ? "空" : extendJson);
    }

}
